package com.chefu.evaluation.controller;

import com.chefu.common.pojo.PageResult;
import com.chefu.common.pojo.R;
import com.chefu.evaluation.dto.POContentDTO;
import com.chefu.evaluation.dto.POProContentDTO;
import com.chefu.evaluation.pojo.PartsOrderEval;
import com.chefu.evaluation.service.PartsOrderEvalService;
import com.chefu.evaluation.vo.ContentVO;
import com.chefu.evaluation.vo.POProSearchVO;
import com.chefu.evaluation.vo.POSearchVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/evaluation/partsOrder")
public class PartsOrderEvalController {
    @Autowired
    private PartsOrderEvalService partsOrderEvalService;

    @ApiOperation(value = "分页查询部件评价数据")
    @GetMapping("/page")
    public R findByPage(@ApiParam(value = "页码", example = "1") @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                        @ApiParam(value = "每页条数", example = "10") @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                        @ModelAttribute POSearchVO poSearchVO) {
        PageResult<PartsOrderEval> pageResult = partsOrderEvalService.findByPage(pageNum, pageSize, poSearchVO);
        return R.ok().data("pageResult", pageResult);
    }

    @ApiOperation(value = "车主添加部件订单评论")
    @PostMapping
    public R saveEvaluation(@ApiParam(value = "订单id", example = "1377143506174300160") @RequestParam(name = "orderId") String orderId,
                            @ModelAttribute ContentVO poContentVO) {
        partsOrderEvalService.saveEvaluation(orderId, poContentVO);
        return R.ok();
    }

    @ApiOperation(value = "根据车主id查询部件订单评价内容")
    @GetMapping("/of/carOwner")
    public R findByCarOwner(@ApiParam(value = "页码", example = "1") @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                            @ApiParam(value = "每页条数", example = "2") @RequestParam(name = "pageSize", defaultValue = "2") Integer pageSize) {
        PageResult<POContentDTO> pageResult = partsOrderEvalService.findByCarOwner(pageNum, pageSize);
        return R.ok().data("pageResult", pageResult);
    }

    @ApiOperation(value = "根据部件商id查询部件订单评价内容")
    @GetMapping("of/partsProvider")
    public R findByPartsProvider(@ApiParam(value = "页码", example = "1") @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                 @ApiParam(value = "每页条数", example = "10") @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                 @ModelAttribute POProSearchVO poProSearchVO) {
        PageResult<POProContentDTO> pageResult = partsOrderEvalService.findByPartsProvider(pageNum, pageSize, poProSearchVO);
        return R.ok().data("pageResult", pageResult);
    }

    @ApiOperation(value = "根据评论id删除部件评价")
    @DeleteMapping()
    public R deleteEvaluation(@ApiParam(value = "评论id", example = "60635f9c8e45f23350b9676e") @RequestParam(name = "id") String id){
        partsOrderEvalService.deleteEvaluation(id);
        return R.ok();
    }
}
